import 'package:flutter/material.dart';
import 'package:flutter_app/bean/weather.dart';
import 'package:flutter_app/http/http_utils.dart';

//Json解析
class JsonDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Json解析'),
        ),
        body: Container(
            alignment: Alignment.center,
            child: RaisedButton(
                child: Text('请求'),
                onPressed: _toRequest
            )
        ));
  }

  _toRequest() {
    HttpUtils()
        .get("http://t.weather.sojson.com/api/weather/city/101030100")
        .then((response) {
      Weather weather = Weather.fromJson(response);
      print(weather.cityInfo.city);
    });
  }
}
